<!DOCTYPE html>
<html lang="zh-cmn-Hans" xmlns:th="http://www.thymeleaf.org">

<head th:replace="menu/import::semantic">
<meta charset="utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1" />

<title>人员信息管理页面</title>
</head>
<body class="layui-layout-body">
	<div class="layui-body" style="margin-top: 20px">
		<!-- 内容主体区域 -->
		<div class="ui main container">
			<div class="ui clearing segment">
				<form th:action="@{/personManage}" id="filterForm" class="ui form"
					method="get">
					<div class="inline fields">
						<div class="field">
							<label>人名</label> <input type="text" name="personName"
								placeholder="可模糊搜索" th:value="${personManage.personName}" />
						</div>
						<label>状态：</label>
						<div class="field">
							<div class="ui fluid search selection dropdown"
								style="width: 150px">
								<input type="hidden" name="status"
									th:value="${personManage.status}">
								<div class="default text">--请选择--</div>
								<i class="dropdown icon"></i>
								<div class="menu">
									<div class="item" data-value="">--请选择--</div>
									<div class="item"
										th:each="statusEnum : ${T(com.ww.springboot.boot.common.PersonManageEnum.statusEnum).values()}"
										th:data-value="${statusEnum.value}"
										th:text="${statusEnum.name}"></div>
								</div>
							</div>
						</div>

						<div class="ui buttons">
							<button class="ui red button" type="submit">查询</button>
						</div>
						<div class="ui buttons">
							<button id="clear" class="ui white button" type="button"
								onclick="clearIs()">重置</button>
						</div>

					</div>
				</form>
			</div>

			<div class="ui buttons">
				<button class="ui red button" type="button" onclick="addDetail()">
					添加</button>
			</div>
			<div class="ui buttons">
				<button class="ui red button" type="button" onclick="doDelect()">移除</button>
			</div>
			
			<div class="ui  floated buttons">
            <a class="ui red button" th:href="@{/personManage/upload}"
                >导入</a>
            </div>

			<a th:href="@{/excelTemplate/personTemplate.xlsx}"><button
					class="ui red button">模板下载</button></a>
			<div class="ui buttons">
                <button class="ui red button" type="button" onclick="exportToExcel()">一键导出</button>
            </div>

			<div style="overflow: auto; margin-top: 5px">
				<form action="#" id="form" class="ui form" method="post">
					<table class="ui red table">
						<thead>
							<tr class="single line">
								<th><input type="checkbox" name="chk_all" id="chk_all"
									class="check_article" /></th>
								<th>人名</th>
								<th>状态</th>
								<th>结果</th>
								<th>简历</th>
								
							</tr>
						</thead>
						<tbody th:if="${list}">
							<tr th:each="one : ${list}">
								<td><input type="checkbox" id="chk_list" name="chk_list"
									class="check_article" th:value="${one.id}" /></td>
								<td><a href="#"
									th:onclick="'Getdetail(\'' + ${one.id} + '\');'"
									th:text="${one.personName}"></a></td>
								<td><span th:if="${one.status != null}"
									th:switch="${one.status.toString()}"> <span
										th:case="'0'">参加面试</span> <span
										th:case="'1'">初试</span> <span 
										th:case="'2'">复试</span><span
                                        th:case="'3'">终试</span>
								</span></td>
								<td><span th:if="${one.type != null}"
                                    th:switch="${one.type.toString()}"> <span
                                        th:case="'0'">等待结果</span> <span style = "color :#7CFC00"
                                        th:case="'1'">是/通过</span> <span style = "color :#CD2626"
                                        th:case="'2'">否/淘汰</span>
                                </span></td>
                                <td><a href="#"
                                    th:onclick="'GetResume(\'' + ${one.id} + '\');'"
                                    th:text="下载"></a></td>
							</tr>
						</tbody>
					</table>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">

$(function () {
    $(".ui.dropdown").dropdown();
  })
	function clearIs() {
		$("input").each(function() {
			var value = $(this).val("");
		});
	}

	$(function() {
		//全选和全不选
		$('#chk_all').bind('click', function() {
			if (this.checked) { //全选
				$("input[name='chk_list']").each(function() {
					$(this).prop('checked', true);
				})
			} else { //全不选
				$("input[name='chk_list']").each(function() {
					$(this).prop('checked', false);
				})
			}
		});
		//所有的子项选中或者不全选中后，全选按钮也选中或者不选中
		var allLength = $("input[name='chk_list']").length; //所有的checkbox的长度
		$("input[name='chk_list']")
				.each(
						function() {
							$(this)
									.bind(
											'click',
											function() {
												var selectedLength = $("input[name='chk_list']:checked").length;//所有的选中的checkbox的长度
												if (selectedLength == allLength) {
													$('#chk_all').prop(
															"checked", true);//全选按钮
												} else {
													$('#chk_all').prop(
															"checked", false);
												}

											})

						})
	})

	function addDetail() {
		$.ajax({
			type : "GET",
			url : "personManage/addpre",
			cache : false,
			timeout : 600000,
			success : function(data) {
				layer.open({
					type : 1,
					title : '系统参数添加页面',
					skin : 'layui-layer-rim', //样式类名
					anim : 2,
					area : [ '800px', '400px' ], //宽高
					shadeClose : false, //开启遮罩关闭
					content : data
				});
			},
		});
	}

	function doDelect() {
		obj = document.getElementsByName("chk_list");
		s = "";
		for (var i = 0; i < obj.length; i++) {
			if (obj[i].checked)
				s += obj[i].value + ','; //如果选中，将value添加到变量s中 
		}
		s = s.substring(0, s.length - 1);
		if (s == "") {
			alert("请勾选需要删除的信息！");
		} else {
			if (confirm("您真的确定要删除吗？\n请确认！") == true) {
				$.ajax({
					type : "GET",
					url : "personManage/delete",
					data : {
						"ids" : s
					},
					cache : false,
					timeout : 600000,
					success : function(data) {
						window.location.reload();
						$("input[name='chk_all']").each(function() {
							$(this).prop('checked', false);
						})
						$("input[name='chk_list']").each(function() {
							$(this).prop('checked', false);
						})
					},
					error : function(jqXHR, textStatus, errorThrown) {
						window.location.reload();
					}
				});

			} else {

				alert("已取消！");
			}
		}

	}

	function Getdetail(id) {
	    $.ajax({
	        type: "GET",
	        url: "personManage/queryDetial",
	        data: {id},
	        cache: false,
	        timeout: 600000,
	        success: function (data) {
	            layer.open({
	              type: 1,
	              title: '修改页面',
	              skin: 'layui-layer-rim', //样式类名
	              anim: 2,
	              area: ['800px', '400px'], //宽高
	              shadeClose: false, //开启遮罩关闭
	              content: data
	            });
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert("error");
	            alert(jqXHR.responseText);
	        }
	    });
	}
	
	function exportToExcel(){
        var str=location.href; //取得整个地址栏
        var num=str.indexOf("?") 
        str=str.substr(num+1); 
       window.location.href ="personManage/dataToExcel?"+str;
   }
</script>
</html>